package com.wk.code.wkserver.config;

import com.wk.code.wkserver.constant.Constant;
import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author wq
 * @version 1.0
 * @date 2021/05/13 13:45
 */
@Configuration
@Slf4j
public class RedissonConfig {

    @Value("${spring.redis.host}")
    private String server;

    @Value("${spring.redis.port}")
    private String port;

    @Value("${spring.redis.password}")
    private String password;

    @Bean
    @Primary
    public RedissonClient getClient() {
        Config config = new Config();
        config.useSingleServer().setAddress(Constant.REDISSON_PREFIX + server + ":" + port).
                setPassword(password);
        RedissonClient redisson = Redisson.create(config);
        log.info("redisson init success:" + "server:" + server + " port:" + port);
        return redisson;
    }
}
